package com.lxhll.personnel.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lxhll.personnel.core.P;
import com.lxhll.personnel.dao.ResignEmployeeDao;
import com.lxhll.personnel.entity.ResignEmployee;
import com.lxhll.personnel.service.EmployeeService;
import com.lxhll.personnel.service.ResignEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.Map;

/**
 * (ResignEmployeeDao.xml)表服务实现类
 *
 * @author makejava
 * @since 2021-07-24 10:15:43
 */
@Service("resignEmployeeService")
public class ResignEmployeeServiceImpl extends ServiceImpl<ResignEmployeeDao, ResignEmployee> implements ResignEmployeeService {
    @Autowired
    private EmployeeService employeeService;
    @Override
    public IPage<Map<String, Object>> resignList(Map<String, Object> params) {
        IPage<Map<String, Object>> page=this.baseMapper.selectResignEmployee(P.page(params),params);
        return page;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveResign(ResignEmployee resignEmployee) {
        //员工逻辑删除（离职）
        employeeService.removeById(resignEmployee.getEmployeeId());
        //添加离职信息表数据
        resignEmployee.setResignDate(LocalDate.now());
        this.save(resignEmployee);
        return true;
    }
}
